package com.kgcx.schedule.controller;

import com.kgcx.schedule.service.BaseBusinessService;

public abstract class BaseBusinessController<P, E> extends SuperController {
    protected abstract BaseBusinessService<P, E> getService();

//    @SuppressWarnings({ "unchecked", "rawtypes" })
//    protected ResponseResult treeEntities() {
//        ParameterMap params = $params();
//        List entities = getService().selectEntityListPage(params);
//        Page<TreeNodeEntity> page = params.page(entities);
//        page.setItems(TreeUtil.listToTree(entities));
//        if (!$bool("tree", false)) {
//            page.setItems(TreeUtil.treeToList(page.getItems()));
//        }
//        return new ResponseResult(new Result(page), HttpStatus.OK);
//    }
//
//    protected ResponseResult listEntities() {
//        ParameterMap params = $params();
//        List<E> entities = getService().selectEntityListPage(params);
//        return new ResponseResult(new Result(params.page(entities)), HttpStatus.OK);
//    }
//
//    protected ResponseResult createEntity(E entity, UriComponentsBuilder ucBuilder) {
//        getService().insertEntity(entity);
//
//        HttpHeaders headers = new HttpHeaders();
//        headers.setLocation(ucBuilder.path("/{id}").buildAndExpand(entity.getF_id()).toUri());
//        return new ResponseResult(new Result(entity), headers, HttpStatus.CREATED);
//    }
//
//    protected ResponseResult getEntity(P primaryKey) {
//        E entity = getService().selectEntity(primaryKey);
//        fillAttachment(entity);
//
//        return new ResponseResult(new Result(entity), HttpStatus.OK);
//    }
//
//    protected ResponseResult updateEntity(P primaryKey, E entity) {
//        getService().updateEntity(primaryKey, entity);
//        return new ResponseResult(new Result(entity), HttpStatus.OK);
//    }
//
//    protected ResponseResult deleteEntity(P primaryKey) {
//        getService().deleteEntity(primaryKey);
//
//        // 这里我们把执行结果通过state和msg字段返回给客户端，所以返回的状态码从204改为200。
//        // 返回码具体意义请参考HTTP协议：https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
//        // return new ResponseEntity<MapEntity>(success(), HttpStatus.NO_CONTENT);
//        return new ResponseResult(new Result(), HttpStatus.OK);
//    }
}
